package com.qk.management.controller;

import com.qk.constant.BusinessConstant;
import com.qk.dto.business.BusinessDTO;
import com.qk.dto.business.BusinessPoolDTO;
import com.qk.dto.business.BusinessTrackDTO;
import com.qk.entity.Business;
import com.qk.management.service.BusinessService;
import com.qk.result.Result;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/13 20:40
 * @Description: 商机管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/businesses")
@RequiredArgsConstructor
public class BusinessController {

    private final BusinessService businessService;

    @PutMapping("/back/{id}")
    public Result backPublicSea(@PathVariable Integer id) {
        businessService.backPublicSea(id);
        return Result.success();
    }

    @PostMapping("/toCustomer/{id}")
    public Result convertToCustomer(@PathVariable Integer id) {
        businessService.convertToCustomer(id);
        return Result.success();
    }

    @PutMapping("")
    public Result trackBusiness(@RequestBody BusinessTrackDTO businessTrackDTO){
        businessService.trackBusiness(businessTrackDTO);
        return Result.success();
    }

    @PutMapping("/assign/{businessId}/{userId}")
    public Result assignBusiness(@PathVariable Integer businessId,
                                 @PathVariable Integer userId) {
        businessService.updateBusinessById(businessId,userId);
        return Result.success();
    }

    @PostMapping("")
    public Result addBusiness(@RequestBody Business business) {
        businessService.insert(business);
        return Result.success();
    }

    @GetMapping("pool")
    public Result selectBusinessPool(BusinessPoolDTO businessPoolDTO) {
        return Result.success(businessService.selectBusinessPool(businessPoolDTO));
    }

    @GetMapping("{id}")
    public Result selectBusinessById(@PathVariable("id") Integer id) {
        return Result.success(businessService.getBusinessById(id));
    }

    @GetMapping("")
    public Result selectBusinessByPage(BusinessDTO businessDTO) {
        return Result.success(businessService.selectBusinessByPage(businessDTO));
    }
}
